package org.force4spring.query;

import com.sforce.soap.partner.DescribeSObjectResult;
import com.sforce.soap.partner.Field;

/**
 * Implementation of <code>expression</code> that simulates '*' notation SQL.Since SOQL does
 * not permit to select 'all' fields this expression implementation concatenates all fields
 * of specified object.
 * 
 * @author Max Rudman
 */
public class StarExpression implements Expression {
	private DescribeSObjectResult metadata;
	
	public StarExpression(DescribeSObjectResult metadata) {
		this.metadata = metadata;
	}

	/**
	 * Returns object metadata used to generate this expression.
	 * 
	 * @return Obejct metadata
	 */
	public DescribeSObjectResult getMetadata() {
		return metadata;
	}

	/**
	 * @see org.force4spring.query.Expression#buildSOQL()
	 */
	public String buildSOQL() {
		StringBuffer result = new StringBuffer();
		Field[] fields = metadata.getFields();
		for (int i=0;i<fields.length;i++) {
			if (i > 0) {
				result.append(",");
			}
			result.append(fields[i].getName());
		}
		return result.toString();
	}
	
	
}
